﻿using System;
using Moebius.Components;
using NUnit.Framework;
using NUnit.Framework.SyntaxHelpers;
using Rhino.Mocks;

namespace Moebius.Tests.Components
{
    [TestFixture]
    public class EntityTests
    {
        private MockRepository mockRepository;
        private World world;

        #region Test Initialization

        [SetUp]
        public void SetUp()
        {
            mockRepository = new MockRepository();
            world = new World();
        }

        #endregion
        #region Tear Down

        [TearDown]
        public void TearDown()
        {
            mockRepository.ReplayAll();
            mockRepository.VerifyAll();
        }

        #endregion

        #region Test: Creating Entity Injects It Into the World

        [Test]
        public void TestCreatingEntityInjectsItIntoTheWorld()
        {
            new Entity(world);
            world.Execute(1);

            Assert.That(world.EntityCount, Is.EqualTo(1));
        }

        #endregion
        #region Test: Entities Are Initialized When They Are Added to the World

        [Test]
        public void TestEntitiesAreInitializedWhenAdded()
        {
            Entity entity = mockRepository.CreateMock<Entity>(world);

            entity.Initialize(null);
            LastCall.IgnoreArguments();

            mockRepository.ReplayAll();

            world.Execute(1);
            Assert.That(entity.CreatedAt, Is.LessThanOrEqualTo(DateTime.Now));

            mockRepository.VerifyAll();
        }

        #endregion

    }
}